package com.atguigu.gmall.payment;


import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

public class AlipayDemo {

    public static void main(String[] args) throws Exception {


        //支付宝的支付客户端准备
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipaydev.com/gateway.do",
                "2021000117665379",
                "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQChGC00Gbtr5/r6720eKnFs5WQTTGAHQLDHY15yjimI1GYhKndaL19FsOdkmSVdGy0CcmRYQAC6PIX4hP1ilcj80hexgv80oDo9vKcCbwBmR6zWtGKI2i3HdR35SLUktmrbaZMfvezZ1ygDSqtznFtHvii816TGdbeZ7NpPuG9i00QL31sCYGxVBuK+jEltJb9SaIdHbY5b8PJa7M8F9hXVNZimrMbUAl38letjzgLpQnUYlFghzgbGa7NPZqhV3lDqFPrbWIaWV/gCDOqTi+fm9dlbDSJzMrE9MFyGZCojWe618BnxlkUTYw34qSYnWsLZpcxTtIHx8N/T5iMLy3cfAgMBAAECggEBAJieeAz5J/gmEkB0XtOKcGUzuikSXZPhdNmhydQL3Uu1toBLZEG7ya4T2FUVRjG8UlsUFv8Iu+e0+VOmYwxoTb9AJ5RUQAYSmrrspOkIUr+Tviq3QPbYhTCHQ3ttp7f9XqU6k1kqLV+AmHbt4hsokc4ZWSz3vDMNSYF5xKZsXJKpgiz4PnLnu/rexDOjXTKouNOsu1/nKlT5xOsgyXzdoRzS6CpKFT/BAQLmX7O2kq3gzP7WP06uvMTO92HCAnTZbUSVVrZ5Ike2Cx5JGRWExQUk5xENw8s97nrHYNUMpc9/K0hVKlyhwIxXfvg2Y6VRSHEcV6w44Mdw6s7igSB+yoECgYEA6YEexcWYwGUuKNZTZ/tO8xVbx0zeQtB89kSYtFArfaPaNiM8rD+Ltdog2jTzLcX6bErMWrk2FK4bLlGxvRF4a5xCnHg66KB1wAz/p+E0zS8u4f3hkJ+2mbTkQQ9YBQcNk5tx56SfVZ0exwRHVrJymkLOf1uDjxWMnaEXDp7UCMECgYEAsJ0420jNXbopGyL/vCapo7PXt92v/ppMy4JVr2Dv7ew+yXVhlYk14jWEUOfHifWP9FJa1HEMw5WBdtVaKP+/qNe1YthUBLaWomXu+pbOhAjw5s5CeFQo9W96C2QwwkADRC9mQC4MjEre6ctICZGsk5DfI7xspbD/QwtmHh1ul98CgYAw/18tsOD0vkaJWy/1Sc6vQ3QWxhJ9grI2Gv7QF2KI4rEPWyWIH215o2PxZdsBZ+G8h5WKFAM9I6ugdJQPUHMsYYW4v6Hc3o7W1eNvntotlBEKavPCHUF7z3F2FXoq0+gNaTjlmq20kVu79zHhB2D07b/XCaT5iVQQX5UvBDUKAQKBgQCvll/kg2jJej9L32vpH3cgbbhV8Gz872LSIW4WwoVHQczadXzjMlsD3rkBxq23FxBbk1UCSLKr8IOaJVtRz5I4xtxqvTAqz2zLYBRLxori8hCvJvkmsGVYPdBUavOe7A1TSNybiiynffhI7/Varh2pSCrQWJCb2nCtszN/VTuSeQKBgQDIkblFFfnykwqZXabJwLTyzlBJZjogJkJqemw68AJIw9bowkRHtDYJZNvs21LcLIMw17n3+QmZBWJi03FFLWg/+1kFT5kWWsuj3p0f2FSo20XPxyX6PCx/xF1pJamlTwVHugdhllHWcMSiDTB9JO5bjb0mW8HBDSkoAd0LUu1kfg==",
                "json",
                "UTF-8",
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkifsDBIk5PFbbes62ywQQDkHLSA7p88ljVcFDUaB3FlqgKNJMts9jkAQ2NggY6Ya7sD6vRvIp+7M3PRrM5O8Zwh6LFQFbsC1guUS61HE6raTNwGx5/EEoWsXhfLB7aaUnTlEoj5As7ehCwGtnHTlmxI/UKO+U8fX87bFMMZa3yGzNA+inn5BqQ7FHsv7Q/MhA3v3P6jRChsUkUrvPXTcpKS+66lFOfmI/68oBkCfL2CfzDZJ5dPq9iSUeYScgHLRZ8Pw9VB+5TMY2A6oFGVJE0ybR3k9kuy9XVaR7t9QSHHTCVS1CgvOWDUEBYS2XetDNR/zSjZbodDbRKPPRfPWXwIDAQAB",
                "RSA2");
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

        Map<String, String> payParam = new HashMap<>();
        payParam.put("out_trade_no","");
        payParam.put("product_code","FAST_INSTANT_TRADE_PAY");
        payParam.put("total_amount","666.66");
        payParam.put("subject","测试支付");

        request.setBizContent(JSONObject.toJSONString(payParam));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if (response.isSuccess()) {
            System.out.println(response.getBody());
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }


}
